package com.ruoyi.product.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.product.domain.ProductSku;
import com.ruoyi.product.service.IProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商品SKUController
 *
 * @author liuhuizhong
 * @date 2025-07-11
 */

@RestController
@RequestMapping("/web/sku")
@Tag(name = "商品SKU接口", description = "提供商品SKU操作")
public class ProductSkuController extends BaseController {
    @Autowired
    private IProductSkuService productSkuService;

    /**
     * 查询商品SKU列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询商品SKU列表", description = "传入SKU查询对象，返回商品SKU列表")
    public AjaxResult list(ProductSku productSku) {
//        startPage();
        List<ProductSku> list = productSkuService.selectProductSkuList(productSku);
        return success(list);
    }

    /**
     * 获取商品SKU详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:sku:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取商品SKU详细信息", description = "传入SKU ID，返回商品SKU详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productSkuService.selectProductSkuById1(id));
    }

    /**
     * 根据用户id获取sku对应优惠券
     */
    @PreAuthorize("@ss.hasPermi('product:sku:query')")
    @GetMapping("/getUCoupon/{userId}")
    @Operation(summary = "根据用户id获取sku对应优惠券", description = "传入用户id，返回sku对应优惠券")
    public AjaxResult getSkuCoupon(@PathVariable("userId") Long userId, @RequestParam Long skuId) {
        return success(productSkuService.getSkuCoupon(userId, skuId));
    }


}
